;;;
;;;
;;;	Author:	Henry C. Francis
;;;		425 N. Ashe St.
;;;		Southern Pines, NC 28387
;;;		http://paracadd.com
;;;		All rights reserved.
;;;
;;;		COPYRIGHT: 	when created
;;;		   EDITED:	10-24-2013
;;;
;;;******************************************************************************
(DEFUN C:BULGEIT ( / pts_edata this_edata this_edata_01 this_edata_02 this_it this_pt this_pt_lst this_vertex this_vertex_10 this_vertex_40 this_vertex_41 this_vertex_42)
  (SETQ this_it (NENTSELP))
  (SETQ this_edata (ENTGET (CAR this_it)))
  (COND
    ((EQ (CDR (ASSOC 0 this_edata)) "VERTEX")
     (SETQ this_edata (subst (cons 42 0.001) (ASSOC 42 this_edata) this_edata))
     (ENTMOD this_edata))
    ((EQ (CDR (ASSOC 0 this_edata)) "LWPOLYLINE")
     (SETQ this_pt (CADR this_it)
           this_pt_lst NIL
           pts_edata this_edata
     )
     (WHILE (ASSOC 10 pts_edata)
       (SETQ this_pt_lst (APPEND this_pt_lst (LIST (ASSOC 10 pts_edata)))
             pts_edata (CDR (MEMBER (LAST this_pt_lst) pts_edata))
       )
     )
     (SETQ this_vertex NIL)
     (FOREACH n (REVERSE (CDR (REVERSE this_pt_lst)))
       (IF (AND (< (DISTANCE (CDR n) this_pt) (DISTANCE (CDR n) (CDADR (MEMBER n this_pt_lst))))
                (< (DISTANCE (CDADR (MEMBER n this_pt_lst)) this_pt) (DISTANCE (CDR n) (CDADR (MEMBER n this_pt_lst))))
                (<= (+(DISTANCE (CDR n) this_pt)(DISTANCE (CDADR (MEMBER n this_pt_lst)) this_pt)) (*(DISTANCE (CDR n) (CDADR (MEMBER n this_pt_lst)))(/ 1.0 (COS (* PI (/ 5.0 180.0))))))
           )
         (PROGN
           (SETQ this_vertex_10 n
                 this_vertex_40 (ASSOC 40 (MEMBER this_vertex_10 this_edata))
                 this_vertex_41 (ASSOC 41 (MEMBER this_vertex_10 this_edata))
                 this_vertex_42 (CONS 42 0.001)
                 this_edata_01 (REVERSE (CDR (MEMBER this_vertex_10 (REVERSE this_edata))))
                 this_edata_02 (MEMBER (CADR (MEMBER this_vertex_10 this_pt_lst)) this_edata)
                 this_edata (APPEND this_edata_01 (LIST this_vertex_10 this_vertex_40 this_vertex_41 this_vertex_42) this_edata_02)
           )
           (ENTMOD this_edata)
         )
       )
     ))
  )
)
;;;******************************************************************************
(DEFUN C:UNBULGEIT ( / this_new_edata pts_edata this_edata this_edata_01 this_edata_02 this_it this_polyename this_pt this_pt_lst this_vertex this_vertex_10 this_vertex_40 this_vertex_41 this_vertex_42)
  (IF ukword NIL (LOAD "ukword" "\nFile UKWORD.LSP not loaded! "))
  (IF from_cloud
    (SETQ unbulgeall "Swap")
    (SETQ unbulgeall (ukword 1 "Unbulge Swap Neither" "Unbulge all vertices, Swap arc sides, or Neither?" (IF unbulgeall "Unbulge" "Neither")))
  )
  (SETQ this_it (NENTSELP))
  (SETQ this_edata (ENTGET (CAR this_it)))
  (IF (EQ unbulgeall "Swap")(SETQ from_cloud T))
  (COND
    ((EQ (CDR (ASSOC 0 this_edata)) "VERTEX")
     (IF (OR (EQ unbulgeall "Unbulge")(EQ unbulgeall "Swap"))
       (PROGN
         (WHILE (NOT (EQ (CDR (ASSOC 0 this_edata)) "SEQEND"))
           (SETQ this_edata (ENTGET (ENTNEXT (CDR (ASSOC -1 this_edata)))))
         )
         (SETQ this_edata (ENTGET (CDR (ASSOC -2 this_edata)))
	       this_polyename (CDR (ASSOC -1 this_edata))
	 )
         (WHILE (NOT (EQ (CDR (ASSOC 0 this_edata)) "SEQEND"))
           (SETQ this_edata (ENTGET (ENTNEXT (CDR (ASSOC -1 this_edata)))))
           (IF (EQ (CDR (ASSOC 0 this_edata)) "SEQEND")
             NIL
             (PROGN
               (SETQ this_edata (SUBST (IF from_cloud (CONS 42 (* -1.0 (CDR (ASSOC 42 this_edata))))(CONS 42 0.0)) (ASSOC 42 this_edata) this_edata))
               (ENTMOD this_edata)
             )
           )
         )
	 (ENTUPD this_polyename)
       )
       (PROGN
         (SETQ this_edata (subst (IF from_cloud (CONS 42 (* -1.0 (CDR (ASSOC 42 this_edata))))(CONS 42 0.0)) (ASSOC 42 this_edata) this_edata))
         (ENTMOD this_edata)
       )
       )
       (SETQ from_cloud NIL)
       (PRINC))
    ((AND (EQ (CDR (ASSOC 0 this_edata)) "LWPOLYLINE") from_cloud)
     (SETQ this_pt (CADR this_it)
           pts_edata this_edata
     )
     (FOREACH n this_edata
       (IF (EQ (CAR n) 42)
         (PROGN
           (SETQ n (CONS 42 (* -1.0 (CDR n))))
           (SETQ this_new_edata (APPEND this_new_edata (LIST n)))
         )
         (SETQ this_new_edata (APPEND this_new_edata (LIST n)))
       )
     )
     (ENTMOD this_new_edata)
     (SETQ from_cloud NIL)
     (PRINC))
    ((EQ (CDR (ASSOC 0 this_edata)) "LWPOLYLINE")
     (SETQ this_pt (CADR this_it)
           this_pt_lst NIL
           pts_edata this_edata
     )
     (WHILE (ASSOC 10 pts_edata)
       (SETQ this_pt_lst (APPEND this_pt_lst (LIST (ASSOC 10 pts_edata)))
             pts_edata (CDR (MEMBER (LAST this_pt_lst) pts_edata))
       )
     )
     (SETQ this_vertex NIL)
     (FOREACH n (REVERSE (CDR (REVERSE this_pt_lst)))
       (IF (AND (< (DISTANCE (CDR n) this_pt) (DISTANCE (CDR n) (CDADR (MEMBER n this_pt_lst))))
                (< (DISTANCE (CDADR (MEMBER n this_pt_lst)) this_pt) (DISTANCE (CDR n) (CDADR (MEMBER n this_pt_lst))))
                (<= (+(DISTANCE (CDR n) this_pt)(DISTANCE (CDADR (MEMBER n this_pt_lst)) this_pt)) (*(DISTANCE (CDR n) (CDADR (MEMBER n this_pt_lst)))(/ 1.0 (COS (* PI (/ 5.0 180.0))))))
           )
         (PROGN
           (SETQ this_vertex_10 n
                 this_vertex_40 (ASSOC 40 (MEMBER this_vertex_10 this_edata))
                 this_vertex_41 (ASSOC 41 (MEMBER this_vertex_10 this_edata))
                 this_vertex_42 (IF from_cloud (CONS 42 (* -1.0 (CDR (ASSOC 42 this_edata))))(CONS 42 0.0))
                 this_edata_01 (REVERSE (CDR (MEMBER this_vertex_10 (REVERSE this_edata))))
                 this_edata_02 (MEMBER (CADR (MEMBER this_vertex_10 this_pt_lst)) this_edata)
                 this_edata (APPEND this_edata_01 (LIST this_vertex_10 this_vertex_40 this_vertex_41 this_vertex_42) this_edata_02)
           )
           (ENTMOD this_edata)
         )
       )
     ))
  )
)